/*
Another game of life with SDL renderer.
Copyright (C) 2009-2010  Julien CLEMENT (andematunum@gmail.com)
*/
/*
	This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _Cell_h_
#define _Cell_h_

class Cell {
	public:
		// Create a new black cell (r=0, g=0, b=0)
		Cell  ();
		~Cell ();
	
		// Initializes the cell randomly:
		// dead (black) or alive (red)
		void initRandom 		(void);

		// Initialized the cell randomly:
		// dead (black) or alive (random rgb triplet different
		// from 0,0,0)
		void initRandomColor	(void);

		// Make this cell die (set to black)
		void die (void);

		// Make this cell get born (color computed as
		// an average color of the neighborhood if
		// speficied, white is the default for a non color
		// version.
		void get_born (unsigned int r=255, unsigned int g=255, unsigned int b=255);

		// Check if the cell is dead (black)
		bool dead  (void);

		// Check if the cell is alive (not black)
		bool alive (void);

		// Add a new neighbor
		void addNeighbor (Cell *neighbor);

		// Evolve that cell according to the neighborhood
		void evolve 		(bool& changed);
		void evolveColor	(bool& changed);

		// Read the cell color
		void getColor (unsigned int& r, unsigned int& g, unsigned int& b);

		void setMate (Cell *mate);

	private:
		void _cpy (void);

	private:
		Cell *_neighbors[8];
		int   _neighborIndex;

		unsigned int _r;
		unsigned int _g;
		unsigned int _b;

		// Mate cell
		Cell * _mate;
};

#endif

